﻿using LinFu.IoC.Interfaces;

namespace CoreEx.Common.Ioc
{
    /// <summary>
    /// Base class for implementing post processors.
    /// </summary>
    /// <typeparam name="TServiceType">The service type that this <see cref="PostProcessorBase{TServiceType}"/> applies to.</typeparam>
    public abstract class PostProcessorBase<TServiceType> : IPostProcessor
    {
        #region IPreProcessor Members

        ///<summary>
        /// Allows a <see cref="T:LinFu.IoC.Interfaces.IPostProcessor" /> instance
        /// to inspect or modify the result of a service request.                   
        ///</summary>
        ///<seealso cref="T:LinFu.IoC.Interfaces.IServiceRequestResult" />
        ///<param name="result">The <see cref="T:LinFu.IoC.Interfaces.IServiceRequestResult" /> created as a result of the container operation.</param>
        public void PostProcess(IServiceRequestResult result)
        {
            if (result.ServiceType == typeof(TServiceType))
                Process(result);
        }

        /// <summary>
        /// Performs the actual processing.
        /// </summary>
        /// <remarks>
        /// This method is only called if the service type matches the type of <typeparamref name="TServiceType"/>
        /// </remarks>
        /// <param name="result">An <see cref="IServiceRequestResult"/> instance that represents the result of the process operation</param>
        public abstract void Process(IServiceRequestResult result);

        #endregion        
    }
}